package com.ruoyi.obtain.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.obtain.domain.EduHelp;
import com.ruoyi.obtain.dto.TransferDto;
import com.ruoyi.obtain.service.IEduHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.obtain.mapper.TTransferMapper;
import com.ruoyi.obtain.domain.TTransfer;
import com.ruoyi.obtain.service.ITTransferService;

/**
 * 移交他人Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-12
 */
@Service
public class TTransferServiceImpl implements ITTransferService 
{
    @Autowired
    private TTransferMapper tTransferMapper;

    @Autowired
    private IEduHelpService eduHelpService;

    /**
     * 查询移交他人
     * 
     * @param id 移交他人主键
     * @return 移交他人
     */
    @Override
    public TTransfer selectTTransferById(Long id)
    {
        return tTransferMapper.selectTTransferById(id);
    }

    /**
     * 查询移交他人列表
     * 
     * @param tTransfer 移交他人
     * @return 移交他人
     */
    @Override
    public List<TTransfer> selectTTransferList(TTransfer tTransfer)
    {
        return tTransferMapper.selectTTransferList(tTransfer);
    }

    /**
     * 新增移交他人
     * 
     * @param tTransferDto 移交他人
     * @return 结果
     */
    @Override
    public int insertTTransfer(TransferDto tTransferDto)
    {

        //判断是否移交给自己
        if(tTransferDto.getTeacherId()==tTransferDto.getNewTeacherId()){
            throw new GlobalException("请不要移交给自己");

        }
        TTransfer tTransfer = new TTransfer();

        tTransfer.setCreatTime(new Date());
        tTransfer.setNewTeacherId(tTransferDto.getNewTeacherId());
        tTransfer.setTeacherId(tTransferDto.getTeacherId());
        tTransfer.setContent(tTransferDto.getContent());
        tTransfer.setStuName(tTransferDto.getStuName());
        //EduHelp eduHelp = eduHelpService.selectEduHelpById(tTransfer.getTeacherId());

        EduHelp eduHelp = new EduHelp();
        eduHelp.setId(tTransferDto.getId());
        eduHelp.setTeacherId(tTransferDto.getNewTeacherId());
        eduHelp.setHelpStates(4);
        eduHelpService.updateEduHelp(eduHelp);

        return tTransferMapper.insertTTransfer(tTransfer);
    }

    /**
     * 修改移交他人
     * 
     * @param tTransfer 移交他人
     * @return 结果
     */
    @Override
    public int updateTTransfer(TTransfer tTransfer)
    {
        return tTransferMapper.updateTTransfer(tTransfer);
    }

    /**
     * 批量删除移交他人
     * 
     * @param ids 需要删除的移交他人主键
     * @return 结果
     */
    @Override
    public int deleteTTransferByIds(Long[] ids)
    {
        return tTransferMapper.deleteTTransferByIds(ids);
    }

    /**
     * 删除移交他人信息
     * 
     * @param id 移交他人主键
     * @return 结果
     */
    @Override
    public int deleteTTransferById(Long id)
    {
        return tTransferMapper.deleteTTransferById(id);
    }
}
